package com.lazyboyl.sharding.proxy.net.frontend;

import com.lazyboyl.sharding.proxy.config.ErrorCode;
import com.lazyboyl.sharding.proxy.net.entity.ShardingLoginInfo;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author linzef
 * @since 2021-06-29
 * 类描述： navicate请求过来的异常处理
 */
public class FrontendTailHandler extends ChannelHandlerAdapter {

    private static final Logger logger = LoggerFactory.getLogger(FrontendTailHandler.class);

    private FrontendConnection connection;

    public FrontendTailHandler(FrontendConnection connection) {
        this.connection = connection;
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        logger.error("Exception caught", cause);
        connection.writeErrMessage(ErrorCode.ERR_EXCEPTION_CAUGHT, cause.getMessage());
        ctx.close();
    }
}
